<?php
namespace bee;
define("ACTION_TYPE_GET_PAGE",         1);
define("ACTION_TYPE_AJAX",             2);
define("ACTION_TYPE_POST_FORM",        4);
define("ACTION_TYPE_JAVASCRIPT",       8);
define("ACTION_TYPE_POST_AJAX_FORM",  16);

define("WIDGET_TEXT",         1);
define("WIDGET_RADIO",        2);
define("WIDGET_OPTION",       4);
define("WIDGET_BUTTON",       8);
define("WIDGET_FILE",        16);
define("WIDGET_LABEL",       32);

abstract class widget extends object
{ public $value;
  public $name;
  public $id;
  public $drawMe = TRUE;

  function getValue()
  {  return $this->value;
  }

  function setValue($value)
  {  $this->value = $value;
  }
  /**
   * @var XMLDataHub
   */
  //public $DSDoc;//21041016 bydy
  /**
   * @var eventDetails
   */
  public $onBlurFn;
  /**
   * @var eventDetails
   */
  public $onClickFn;
  /**
   * @var eventDetails
   */
  public $onDblClickFn;
  /**
   * @var eventDetails
   */
  public $onFocusFn;
  /**
   * @var eventDetails
   */
  public $onKeyDownFn;
  /**
   * @var eventDetails
   */
  public $onKeyPressFn;
  /**
   * @var eventDetails
   */
  public $onKeyUpFn;
  /**
   * @var eventDetails
   */
  public $onMouseDownFn;
  /**
   * @var eventDetails
   */
  public $onMouseMoveFn;
  /**
   * @var eventDetails
   */
  public $onMouseOutFn;
  /**
   * @var eventDetails
   */
  public $onMouseOverFn;
  /**
   * @var eventDetails
   */
  public $onMouseUpFn;
  /**
   * @var form
   */
  public $parent;
  /**
   * @var string
   */
  public $class;

  public $widgetType;

  function __construct($name, $id = "")
  {
    if(!$name)
    { die("*");
      throw new ErrorException("Widget name couldn't be empty", 188, 5, __FILE__, __LINE__);
    }
    $this->name = $name;
    $this->id = $id ?: $name;
    $this->__withEvents = true;
    //$this->DSDoc = XMLDataHub::getInstance();//21041016 bydy
    dispatcher::getInstance()->addObject($this);
  }

  function __wakeup()
  { //echo "<br />WAKEw $this->name " . get_called_class();
    //$this->DSDoc = XMLDataHub::getInstance();//21041016 bydy
    dispatcher::getInstance()->addObject($this);
    //$this->bi
    //die(print_r(dispatcher::getInstance(), true));
  }

  public function bindValue(&$valueRef)
  { $this->value = &$valueRef;
  //echo "<br />FILL TXT: / $this->value /";
  }
  /*
  public function bindValue(&$valueRef)
  {
    $this->value = &$valueRef;
  }
  */
}

class eventDetails extends object
{
  function __construct($action_type, $object_name = "", $extra_params = "", $idToFill = "")
  { $this->action_type      = $action_type;
    $this->object_name      = $object_name;
    $this->extra_params     = $extra_params;
    $this->idToFill         = $idToFill;
  }

  /**
   *
   * @var int
   */
  public $action_type;
  /**
   *
   * @var string
   */
  public $object_name;
  /**
   *
   * @var array
   */
  public $extra_params;
  /**
   *
   * @var string
   */
  public $idToFill;

}